/**
 * 在对象obj中用连续的打点字符串寻找到对象值
 * 
 * @example lookup({a: {b: {c: 100}}}, 'a.b.c')
 *
 * @param {object} obj
 * @param {string} key
 * @return any
 */
function lookup(obj, key) {
  const keys = key.split('.');

  // 设置临时变量，一层一层查找
  let val = obj;
  for (const k of keys) {
    if(val === undefined) {
      console.warn(`Can't read ${k} of undefined`);
      return '';
    };
    val = val[k];
  }
  return val;
}

export default lookup;